package name.katlog.refactor._11processgeneralization;

import java.util.Enumeration;
import java.util.Vector;

/**
 * Created by fw on 2018/4/24
 * 塑造模板函数
 */
public class FormTemPlateMethod {
    class BeforeRefactor {
        /**
         * Created by dell on 2018/4/12
         */
        public class Movie8 {
            public static final int CHILDRENS = 2;
            public static final int REGULAR = 0;
            public static final int NEW_RELEASE = 1;
            private String _title; //名称
            private int _priceCode; //价格（代号）

            private Price8 _price;

            public Movie8(String title, int priceCode) {
                _title = title;
                setPriceCode(priceCode);
            }

            public int getPriceCode() { //取得价格代号
                return _price.getPriceCode();
            }

            public void setPriceCode(int arg) { //设定价格代号
                switch (arg) {
                    case REGULAR:
                        _price = new RegularPrice8();
                        break;
                    case CHILDRENS:
                        _price = new ChildrensPrice8();
                        break;
                    case NEW_RELEASE:
                        _price = new NewReleasePrice8();
                        break;
                    default:
                        throw new IllegalArgumentException("Incorrect Price Code");
                }
            }

            public String getTitle() {
                return _title;
            }

            double getCharge(int daysRented) {
                return _price.getCharge(daysRented);
            }

            int getFrequentRenterPoints(int daysRented) {

                if ((getPriceCode() == Movie8.NEW_RELEASE) && daysRented > 1)
                    return 2;
                return 1;
            }
        }

        abstract class Price8 {
            abstract int getPriceCode(); //取得价格代号

            double getCharge(int daysRented) {
                double result = 0;
                switch (getPriceCode()) {
                    case Movie8.REGULAR:
                        result += 2;
                        if (daysRented > 2) result += (daysRented - 2) * 1.5;
                        break;
                    case Movie8.NEW_RELEASE:
                        result += daysRented * 3;
                        break;
                    case Movie8.CHILDRENS:
                        result += 1.5;
                        if (daysRented > 3) result += (daysRented - 3) * 1.5;
                        break;
                }
                return result;
            }
        }

        class ChildrensPrice8 extends Price8 {
            int getPriceCode() {
                return Movie8.CHILDRENS;
            }
        }

        class NewReleasePrice8 extends Price8 {
            int getPriceCode() {
                return Movie8.NEW_RELEASE;
            }
        }

        class RegularPrice8 extends Price8 {
            int getPriceCode() {
                return Movie8.REGULAR;
            }
        }

        class Rental8 {
            Movie8 _movie; //影片
            private int _daysRented; //租期

            public Rental8(Movie8 movie, int daysRented) {
                _movie = movie;
                _daysRented = daysRented;
            }

            public int getDaysRented() {
                return _daysRented;
            }

            public Movie8 getMovie() {
                return _movie;
            }

            double getCharge() {
                return _movie.getCharge(_daysRented);
            }

            int getFrequentRenterPoints() {
                return _movie.getFrequentRenterPoints(_daysRented);
            }
        }

        class Customer8 {
            private String _name; //姓名
            private Vector _rentals = new Vector(); //租借记。

            public Customer8(String name) {
                _name = name;
            }

            public void addRental(Rental8 arg) {
                _rentals.addElement(arg);
            }

            public String getName() {
                return _name;
            }

            public String statement() {
                double totalAmount = 0;
                int frequentRenterPoints = 0;
                Enumeration rentals = _rentals.elements();
                String result = "Rental Record for " + getName() + "\n";
                while (rentals.hasMoreElements()) {

                    Rental8 each = (Rental8) rentals.nextElement();
                    frequentRenterPoints += each.getFrequentRenterPoints();

                    //show figures for this rental
                    result += "\t" + each.getMovie().getTitle() + "\t" + String.valueOf(each.getCharge()) + "\n";
                }

                //add footer lines
                result += "Amount owed is " + String.valueOf(getTotalCharge()) + "\n";
                result += "You earned " + String.valueOf(frequentRenterPoints) + " frequent renter points";
                return result;
            }

            public String htmlStatement() {
                Enumeration rentals = _rentals.elements();
                String result = "<H1>Rentals for <EM>" + getName() + "</EM></ H1><P>\n";
                while (rentals.hasMoreElements()) {
                    Rental8 each = (Rental8) rentals.nextElement();
                    //show figures for each rental
                    result += each.getMovie().getTitle() + ": " + String.valueOf(each.getCharge()) + "<BR>\n";
                }
                //add footer lines
                result += "<P>You owe <EM>" + String.valueOf(getTotalCharge()) + "</EM><P>\n";
                result += "On this rental you earned <EM>" + String.valueOf(getTotalFrequentRenterPoints()) + "</EM> frequent renter points<P>";
                return result;
            }

            public double getTotalCharge() {
                double result = 0;

                Enumeration elements = _rentals.elements();
                while (elements.hasMoreElements()) {
                    Rental8 rental8 = (Rental8) elements.nextElement();
                    result += rental8.getCharge();
                }

                return result;
            }

            private int getTotalFrequentRenterPoints() {
                int result = 0;

                Enumeration elements = _rentals.elements();
                while (elements.hasMoreElements()) {
                    Rental8 rental8 = (Rental8) elements.nextElement();
                    result += rental8.getFrequentRenterPoints();
                }

                return result;
            }

            private double amountFor(Rental8 aRental) {
                return aRental.getCharge();
            }

        }
    }

    /**
     * 抽取输出语句
     */
    static class Refactor1 {
        class Statement {
            String value(Customer8 customer) {
                return null;
            }
        }

        class TextStatement extends Statement {
            public String value(Customer8 customer) {

                double totalAmount = 0;
                int frequentRenterPoints = 0;
                Enumeration rentals = customer.getRentals().elements();
                String result = "Rental Record for " + customer.getName() + "\n";
                while (rentals.hasMoreElements()) {

                    Rental8 each = (Rental8) rentals.nextElement();
                    frequentRenterPoints += each.getFrequentRenterPoints();

                    //show figures for this rental
                    result += "\t" + each.getMovie().getTitle() + "\t" + String.valueOf(each.getCharge()) + "\n";
                }

                //add footer lines
                result += "Amount owed is " + String.valueOf(customer.getTotalCharge()) + "\n";
                result += "You earned " + String.valueOf(frequentRenterPoints) + " frequent renter points";
                return result;

            }
        }

        class HtmlStatement extends Statement {
            public String value(Customer8 customer) {

                Enumeration rentals = customer.getRentals().elements();
                String result = "<H1>Rentals for <EM>" + customer.getName() + "</EM></ H1><P>\n";
                while (rentals.hasMoreElements()) {
                    Rental8 each = (Rental8) rentals.nextElement();
                    //show figures for each rental
                    result += each.getMovie().getTitle() + ": " + String.valueOf(each.getCharge()) + "<BR>\n";
                }
                //add footer lines
                result += "<P>You owe <EM>" + String.valueOf(customer.getTotalCharge()) + "</EM><P>\n";
                result += "On this rental you earned <EM>" + String.valueOf(customer.getTotalFrequentRenterPoints()) + "</EM> frequent renter points<P>";
                return result;

            }
        }

        /**
         * Created by dell on 2018/4/12
         */
        public class Movie8 {
            public static final int CHILDRENS = 2;
            public static final int REGULAR = 0;
            public static final int NEW_RELEASE = 1;
            private String _title; //名称
            private int _priceCode; //价格（代号）

            private Price8 _price;

            public Movie8(String title, int priceCode) {
                _title = title;
                setPriceCode(priceCode);
            }

            public int getPriceCode() { //取得价格代号
                return _price.getPriceCode();
            }

            public void setPriceCode(int arg) { //设定价格代号
                switch (arg) {
                    case REGULAR:
                        _price = new RegularPrice8();
                        break;
                    case CHILDRENS:
                        _price = new ChildrensPrice8();
                        break;
                    case NEW_RELEASE:
                        _price = new NewReleasePrice8();
                        break;
                    default:
                        throw new IllegalArgumentException("Incorrect Price Code");
                }
            }

            public String getTitle() {
                return _title;
            }

            double getCharge(int daysRented) {
                return _price.getCharge(daysRented);
            }

            int getFrequentRenterPoints(int daysRented) {

                if ((getPriceCode() == Movie8.NEW_RELEASE) && daysRented > 1)
                    return 2;
                return 1;
            }

        }

        abstract class Price8 {
            abstract int getPriceCode(); //取得价格代号

            double getCharge(int daysRented) {
                double result = 0;
                switch (getPriceCode()) {
                    case Movie8.REGULAR:
                        result += 2;
                        if (daysRented > 2) result += (daysRented - 2) * 1.5;
                        break;
                    case Movie8.NEW_RELEASE:
                        result += daysRented * 3;
                        break;
                    case Movie8.CHILDRENS:
                        result += 1.5;
                        if (daysRented > 3) result += (daysRented - 3) * 1.5;
                        break;
                }
                return result;
            }
        }

        class ChildrensPrice8 extends Price8 {
            int getPriceCode() {
                return Movie8.CHILDRENS;
            }
        }

        class NewReleasePrice8 extends Price8 {
            int getPriceCode() {
                return Movie8.NEW_RELEASE;
            }
        }

        class RegularPrice8 extends Price8 {
            int getPriceCode() {
                return Movie8.REGULAR;
            }
        }

        class Rental8 {
            Movie8 _movie; //影片
            private int _daysRented; //租期

            public Rental8(Movie8 movie, int daysRented) {
                _movie = movie;
                _daysRented = daysRented;
            }

            public int getDaysRented() {
                return _daysRented;
            }

            public Movie8 getMovie() {
                return _movie;
            }

            double getCharge() {
                return _movie.getCharge(_daysRented);
            }

            int getFrequentRenterPoints() {
                return _movie.getFrequentRenterPoints(_daysRented);
            }
        }

        class Customer8 {
            private String _name; //姓名
            private Vector _rentals = new Vector(); //租借记。

            public Vector getRentals() {
                return _rentals;
            }

            public Customer8(String name) {
                _name = name;
            }

            public void addRental(Rental8 arg) {
                _rentals.addElement(arg);
            }

            public String getName() {
                return _name;
            }

            public String statement() {
                return new TextStatement().value(this);
            }

            public String htmlStatement() {
                return new HtmlStatement().value(this);
            }

            public double getTotalCharge() {
                double result = 0;

                Enumeration elements = _rentals.elements();
                while (elements.hasMoreElements()) {
                    Rental8 rental8 = (Rental8) elements.nextElement();
                    result += rental8.getCharge();
                }

                return result;
            }

            private int getTotalFrequentRenterPoints() {
                int result = 0;

                Enumeration elements = _rentals.elements();
                while (elements.hasMoreElements()) {
                    Rental8 rental8 = (Rental8) elements.nextElement();
                    result += rental8.getFrequentRenterPoints();
                }

                return result;
            }

            private double amountFor(Rental8 aRental) {
                return aRental.getCharge();
            }

            public void fun() {
                Movie8 movie1 = new Refactor1().new Movie8("moviename", 1);
                Movie8 movie2 = new Refactor1().new Movie8("moviename", 2);
                Rental8 rental2 = new Refactor1().new Rental8(movie1, 2);
                Rental8 rental1 = new Refactor1().new Rental8(movie2, 1);
                Customer8 tom = new Refactor1().new Customer8("tom");
                tom.addRental(rental1);
                tom.addRental(rental2);
                System.out.println(tom.statement());
            }
        }

        //public static void main(String[] args) {
        //    new Refactor1().new Customer8("zhangsan").fun();
        //}

        //public static void main(String[] args) {
        //    Movie8 movie1 = new Refactor1().new Movie8("moviename", 1);
        //    Movie8 movie2 = new Refactor1().new Movie8("moviename", 2);
        //    Rental8 rental2 = new Refactor1().new Rental8(movie1, 2);
        //    Rental8 rental1 = new Refactor1().new Rental8(movie2, 1);
        //    Customer8 tom = new Refactor1().new Customer8("tom");
        //    tom.addRental(rental1);
        //    tom.addRental(rental2);
        //    System.out.println(tom.statement());
        //}
    }

    /**
     * 提取相似函数
     */
    static class Refactor2 {
        class Statement {
            String value(Customer8 customer) {
                return null;
            }
        }

        class TextStatement extends Statement {
            public String value(Customer8 customer) {

                double totalAmount = 0;
                int frequentRenterPoints = 0;
                Enumeration rentals = customer.getRentals().elements();
                String result = headString(customer);
                while (rentals.hasMoreElements()) {

                    Rental8 each = (Rental8) rentals.nextElement();
                    frequentRenterPoints += each.getFrequentRenterPoints();

                    //show figures for this rental
                    result += eachRentalString(each);
                }

                //add footer lines
                result += footString(customer);
                return result;

            }

            private String footString(Customer8 customer) {
                return "Amount owed is " + String.valueOf(customer.getTotalCharge()) + "\n" +
                        "You earned " + String.valueOf(customer.getTotalFrequentRenterPoints()) + " frequent renter points";
            }

            private String eachRentalString(Rental8 each) {
                return "\t" + each.getMovie().getTitle() + "\t" + String.valueOf(each.getCharge()) + "\n";
            }

            private String headString(Customer8 customer) {
                return "Rental Record for " + customer.getName() + "\n";
            }
        }

        class HtmlStatement extends Statement {
            public String value(Customer8 customer) {

                Enumeration rentals = customer.getRentals().elements();
                String result = headerString(customer);
                while (rentals.hasMoreElements()) {
                    Rental8 each = (Rental8) rentals.nextElement();
                    //show figures for each rental
                    result += eachRentalString(each);
                }
                //add footer lines
                result += footerString(customer);
                return result;

            }

            private String footerString(Customer8 customer) {
                return "<P>You owe <EM>" + String.valueOf(customer.getTotalCharge()) + "</EM><P>\n"
                        + "On this rental you earned <EM>" + String.valueOf(customer.getTotalFrequentRenterPoints()) + "</EM> frequent renter points<P>";
            }

            private String eachRentalString(Rental8 each) {
                return each.getMovie().getTitle() + ": " + String.valueOf(each.getCharge()) + "<BR>\n";
            }

            private String headerString(Customer8 customer) {
                return "<H1>Rentals for <EM>" + customer.getName() + "</EM></ H1><P>\n";
            }
        }

        /**
         * Created by dell on 2018/4/12
         */
        public class Movie8 {
            public static final int CHILDRENS = 2;
            public static final int REGULAR = 0;
            public static final int NEW_RELEASE = 1;
            private String _title; //名称
            private int _priceCode; //价格（代号）

            private Price8 _price;

            public Movie8(String title, int priceCode) {
                _title = title;
                setPriceCode(priceCode);
            }

            public int getPriceCode() { //取得价格代号
                return _price.getPriceCode();
            }

            public void setPriceCode(int arg) { //设定价格代号
                switch (arg) {
                    case REGULAR:
                        _price = new RegularPrice8();
                        break;
                    case CHILDRENS:
                        _price = new ChildrensPrice8();
                        break;
                    case NEW_RELEASE:
                        _price = new NewReleasePrice8();
                        break;
                    default:
                        throw new IllegalArgumentException("Incorrect Price Code");
                }
            }

            public String getTitle() {
                return _title;
            }

            double getCharge(int daysRented) {
                return _price.getCharge(daysRented);
            }

            int getFrequentRenterPoints(int daysRented) {

                if ((getPriceCode() == Movie8.NEW_RELEASE) && daysRented > 1)
                    return 2;
                return 1;
            }

        }

        abstract class Price8 {
            abstract int getPriceCode(); //取得价格代号

            double getCharge(int daysRented) {
                double result = 0;
                switch (getPriceCode()) {
                    case Movie8.REGULAR:
                        result += 2;
                        if (daysRented > 2) result += (daysRented - 2) * 1.5;
                        break;
                    case Movie8.NEW_RELEASE:
                        result += daysRented * 3;
                        break;
                    case Movie8.CHILDRENS:
                        result += 1.5;
                        if (daysRented > 3) result += (daysRented - 3) * 1.5;
                        break;
                }
                return result;
            }
        }

        class ChildrensPrice8 extends Price8 {
            int getPriceCode() {
                return Movie8.CHILDRENS;
            }
        }

        class NewReleasePrice8 extends Price8 {
            int getPriceCode() {
                return Movie8.NEW_RELEASE;
            }
        }

        class RegularPrice8 extends Price8 {
            int getPriceCode() {
                return Movie8.REGULAR;
            }
        }

        class Rental8 {
            Movie8 _movie; //影片
            private int _daysRented; //租期

            public Rental8(Movie8 movie, int daysRented) {
                _movie = movie;
                _daysRented = daysRented;
            }

            public int getDaysRented() {
                return _daysRented;
            }

            public Movie8 getMovie() {
                return _movie;
            }

            double getCharge() {
                return _movie.getCharge(_daysRented);
            }

            int getFrequentRenterPoints() {
                return _movie.getFrequentRenterPoints(_daysRented);
            }
        }

        class Customer8 {
            private String _name; //姓名
            private Vector _rentals = new Vector(); //租借记。

            public Vector getRentals() {
                return _rentals;
            }

            public Customer8(String name) {
                _name = name;
            }

            public void addRental(Rental8 arg) {
                _rentals.addElement(arg);
            }

            public String getName() {
                return _name;
            }

            public String statement() {
                return new TextStatement().value(this);
            }

            public String htmlStatement() {
                return new HtmlStatement().value(this);
            }

            public double getTotalCharge() {
                double result = 0;

                Enumeration elements = _rentals.elements();
                while (elements.hasMoreElements()) {
                    Rental8 rental8 = (Rental8) elements.nextElement();
                    result += rental8.getCharge();
                }

                return result;
            }

            private int getTotalFrequentRenterPoints() {
                int result = 0;

                Enumeration elements = _rentals.elements();
                while (elements.hasMoreElements()) {
                    Rental8 rental8 = (Rental8) elements.nextElement();
                    result += rental8.getFrequentRenterPoints();
                }

                return result;
            }

            private double amountFor(Rental8 aRental) {
                return aRental.getCharge();
            }

            public void fun() {
                Movie8 movie1 = new Refactor2().new Movie8("moviename", 1);
                Movie8 movie2 = new Refactor2().new Movie8("moviename", 2);
                Rental8 rental2 = new Refactor2().new Rental8(movie1, 2);
                Rental8 rental1 = new Refactor2().new Rental8(movie2, 1);
                Customer8 tom = new Refactor2().new Customer8("tom");
                tom.addRental(rental1);
                tom.addRental(rental2);
                System.out.println(tom.statement());
            }
        }

        //public static void main(String[] args) {
        //    new Refactor2().new Customer8("zhangsan").fun();
        //}

        //public static void main(String[] args) {
        //    Movie8 movie1 = new Refactor1().new Movie8("moviename", 1);
        //    Movie8 movie2 = new Refactor1().new Movie8("moviename", 2);
        //    Rental8 rental2 = new Refactor1().new Rental8(movie1, 2);
        //    Rental8 rental1 = new Refactor1().new Rental8(movie2, 1);
        //    Customer8 tom = new Refactor1().new Customer8("tom");
        //    tom.addRental(rental1);
        //    tom.addRental(rental2);
        //    System.out.println(tom.statement());
        //}
    }

    /**
     * 向父类进行抽取
     */
    static class Refactor3 {
        abstract class Statement {
            String value(Customer8 customer) {

                double totalAmount = 0;
                int frequentRenterPoints = 0;
                Enumeration rentals = customer.getRentals().elements();
                String result = headerString(customer);
                while (rentals.hasMoreElements()) {

                    Rental8 each = (Rental8) rentals.nextElement();
                    frequentRenterPoints += each.getFrequentRenterPoints();

                    //show figures for this rental
                    result += eachRentalString(each);
                }

                //add footer lines
                result += footerString(customer);
                return result;

            }

            protected abstract String footerString(Customer8 customer);

            protected abstract String eachRentalString(Rental8 each);

            protected abstract String headerString(Customer8 customer);
        }

        class TextStatement extends Statement {

            protected String footerString(Customer8 customer) {
                return "Amount owed is " + String.valueOf(customer.getTotalCharge()) + "\n" +
                        "You earned " + String.valueOf(customer.getTotalFrequentRenterPoints()) + " frequent renter points";
            }

            protected String eachRentalString(Rental8 each) {
                return "\t" + each.getMovie().getTitle() + "\t" + String.valueOf(each.getCharge()) + "\n";
            }

            protected String headerString(Customer8 customer) {
                return "Rental Record for " + customer.getName() + "\n";
            }
        }

        class HtmlStatement extends Statement {

            protected String footerString(Customer8 customer) {
                return "<P>You owe <EM>" + String.valueOf(customer.getTotalCharge()) + "</EM><P>\n"
                        + "On this rental you earned <EM>" + String.valueOf(customer.getTotalFrequentRenterPoints()) + "</EM> frequent renter points<P>";
            }

            protected String eachRentalString(Rental8 each) {
                return each.getMovie().getTitle() + ": " + String.valueOf(each.getCharge()) + "<BR>\n";
            }

            protected String headerString(Customer8 customer) {
                return "<H1>Rentals for <EM>" + customer.getName() + "</EM></ H1><P>\n";
            }
        }

        /**
         * Created by dell on 2018/4/12
         */
        public class Movie8 {
            public static final int CHILDRENS = 2;
            public static final int REGULAR = 0;
            public static final int NEW_RELEASE = 1;
            private String _title; //名称
            private int _priceCode; //价格（代号）

            private Price8 _price;

            public Movie8(String title, int priceCode) {
                _title = title;
                setPriceCode(priceCode);
            }

            public int getPriceCode() { //取得价格代号
                return _price.getPriceCode();
            }

            public void setPriceCode(int arg) { //设定价格代号
                switch (arg) {
                    case REGULAR:
                        _price = new RegularPrice8();
                        break;
                    case CHILDRENS:
                        _price = new ChildrensPrice8();
                        break;
                    case NEW_RELEASE:
                        _price = new NewReleasePrice8();
                        break;
                    default:
                        throw new IllegalArgumentException("Incorrect Price Code");
                }
            }

            public String getTitle() {
                return _title;
            }

            double getCharge(int daysRented) {
                return _price.getCharge(daysRented);
            }

            int getFrequentRenterPoints(int daysRented) {

                if ((getPriceCode() == Movie8.NEW_RELEASE) && daysRented > 1)
                    return 2;
                return 1;
            }

        }

        abstract class Price8 {
            abstract int getPriceCode(); //取得价格代号

            double getCharge(int daysRented) {
                double result = 0;
                switch (getPriceCode()) {
                    case Movie8.REGULAR:
                        result += 2;
                        if (daysRented > 2) result += (daysRented - 2) * 1.5;
                        break;
                    case Movie8.NEW_RELEASE:
                        result += daysRented * 3;
                        break;
                    case Movie8.CHILDRENS:
                        result += 1.5;
                        if (daysRented > 3) result += (daysRented - 3) * 1.5;
                        break;
                }
                return result;
            }
        }

        class ChildrensPrice8 extends Price8 {
            int getPriceCode() {
                return Movie8.CHILDRENS;
            }
        }

        class NewReleasePrice8 extends Price8 {
            int getPriceCode() {
                return Movie8.NEW_RELEASE;
            }
        }

        class RegularPrice8 extends Price8 {
            int getPriceCode() {
                return Movie8.REGULAR;
            }
        }

        class Rental8 {
            Movie8 _movie; //影片
            private int _daysRented; //租期

            public Rental8(Movie8 movie, int daysRented) {
                _movie = movie;
                _daysRented = daysRented;
            }

            public int getDaysRented() {
                return _daysRented;
            }

            public Movie8 getMovie() {
                return _movie;
            }

            double getCharge() {
                return _movie.getCharge(_daysRented);
            }

            int getFrequentRenterPoints() {
                return _movie.getFrequentRenterPoints(_daysRented);
            }
        }

        class Customer8 {
            private String _name; //姓名
            private Vector _rentals = new Vector(); //租借记。

            public Vector getRentals() {
                return _rentals;
            }

            public Customer8(String name) {
                _name = name;
            }

            public void addRental(Rental8 arg) {
                _rentals.addElement(arg);
            }

            public String getName() {
                return _name;
            }

            public String statement() {
                return new TextStatement().value(this);
            }

            public String htmlStatement() {
                return new HtmlStatement().value(this);
            }

            public double getTotalCharge() {
                double result = 0;

                Enumeration elements = _rentals.elements();
                while (elements.hasMoreElements()) {
                    Rental8 rental8 = (Rental8) elements.nextElement();
                    result += rental8.getCharge();
                }

                return result;
            }

            private int getTotalFrequentRenterPoints() {
                int result = 0;

                Enumeration elements = _rentals.elements();
                while (elements.hasMoreElements()) {
                    Rental8 rental8 = (Rental8) elements.nextElement();
                    result += rental8.getFrequentRenterPoints();
                }

                return result;
            }

            private double amountFor(Rental8 aRental) {
                return aRental.getCharge();
            }

            public void fun() {
                Movie8 movie1 = new Refactor3().new Movie8("moviename", 1);
                Movie8 movie2 = new Refactor3().new Movie8("moviename", 2);
                Rental8 rental2 = new Refactor3().new Rental8(movie1, 2);
                Rental8 rental1 = new Refactor3().new Rental8(movie2, 1);
                Customer8 tom = new Refactor3().new Customer8("tom");
                tom.addRental(rental1);
                tom.addRental(rental2);
                System.out.println(tom.statement());
            }
        }

        public static void main(String[] args) {
            new Refactor3().new Customer8("zhangsan").fun();
        }

        //public static void main(String[] args) {
        //    Movie8 movie1 = new Refactor1().new Movie8("moviename", 1);
        //    Movie8 movie2 = new Refactor1().new Movie8("moviename", 2);
        //    Rental8 rental2 = new Refactor1().new Rental8(movie1, 2);
        //    Rental8 rental1 = new Refactor1().new Rental8(movie2, 1);
        //    Customer8 tom = new Refactor1().new Customer8("tom");
        //    tom.addRental(rental1);
        //    tom.addRental(rental2);
        //    System.out.println(tom.statement());
        //}
    }

}
